package com.mzm.util.persistency;

/**
 * 
 * @author Daniel Orr
 *
 */
public class QueryBlock {
	private String header;
	protected StringBuilder content = new StringBuilder();
	
	private int indentSize = 1;

	public QueryBlock(String header) {
		this.header = header;
	}

	public boolean isEmpty(){
		return content.length() == 0;
	}

	public void increaseIndent(){
		indentSize++;
	}

	public void decreaseIndent(){
		indentSize--;
	}
	
	public void append(String s){
		append(s, null);
	}
	
	public void append(String s, String pre){
		if(content.length() == 0){
			content.append(s);
			content.append("\n");
		}
		else {
			indent();
			if (pre != null) {
				content.append(pre);
			}
			content.append(s);
			content.append(" \n");		
		}
	}

	public String getContent(){
		return content.toString().trim();
	}
	
	@Override
	public String toString() {
		if(content.length() == 0){
			return "";
		}
		return header+"\n\t"+content.toString();
	}
	
	private void indent(){
		for (int i = 0; i < indentSize; i++) {
			content.append("\t");
		}
	}
}
